<template>
  <div>
    <el-form :model="form" :rules="rules" ref="UpAdd">
      <el-form-item label="省/市/区">
        <el-cascader :options="options" :props="setProp" clearable @change="handleChange" >
        </el-cascader>
      </el-form-item>
      <el-form-item label="详细地址" prop="diAddress">
        <el-input v-model="form.diAddress" autocomplete="off"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="closeDig()">取 消</el-button>
      <el-button type="primary" @click="UpAdd">确 定</el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    options: {
      type: Array,
      required: true
    },
    closeDig: {
      type: Function,
      required: true
    }
  },
  data() {
    return {
      form: {
        diAddress: ''
      },
      label: [],
      setProp: {
        value: 'name',
        label: 'name',
        children: 'districts'
      },
      rules: {
        diAddress: [
          {
            required: true,
            // 验证不通过时，错误提示文案
            message: '当前字段是必填的'
          }
        ]
      }
    }
  },
  methods: {
    // 改变连选时
    handleChange(label) {
      this.label = label
    },
    // 提交表单
    UpAdd() {
      this.$refs.UpAdd.validate((valid) => {
        if (valid) {
          // 验证通过
          const addUpdata = [...this.label, this.form.diAddress]
          this.$emit('addUpdata', addUpdata)
        } else {
          // 验证不通过
          this.$message({
            type: 'error',
            message: '表单验证不通过'
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
